# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Contributor: Cebtenzzre <cebtenzzre (at) gmail (dot) com>
# Contributor: Andy Weidenbaum <archbaum@gmail.com>

pkgname=libwslay
pkgver=1.1.1
pkgrel=5
pkgdesc='WebSocket library'
arch=(loong64 x86_64)
provides=(wslay)
replaces=(wslay)
makedepends=(python-sphinx)
checkdepends=(cunit)
optdepends=('nettle: needed for wslay_testclient')
url='https://github.com/tatsuhiro-t/wslay'
license=(MIT)
source=("$pkgname-$pkgver.tar.bz2::https://github.com/tatsuhiro-t/wslay/releases/download/release-$pkgver/wslay-$pkgver.tar.bz2"
        sphinx-4.patch)
b2sums=('e5b5e7435e1e3a82cef4407f2a5fbcf4168f2814546074d8ee5aa70f36acabc648bc58f14aaee53bc6be7ab7e18c39a4f8e16fba507dc85f19ee4f79a827be6e'
        '12dc00c3dfcf29a0263b93638164ab9e99a9672962714392cf8f28421498d138a83779a267f59892b579f66dfc4b7fca8c8b1a3662040d9dc29d1841ebe42ea9')

prepare() {
  cd wslay-$pkgver
  patch -Np1 -i ../sphinx-4.patch
}

build() {
  cd wslay-$pkgver
  autoreconf -i
  ./configure \
    --libexecdir=/usr/lib/wslay \
    --localstatedir=/var/lib/wslay \
    --prefix=/usr \
    --sbindir=/usr/bin \
    --sharedstatedir=/usr/share/wslay \
    --sysconfdir=/etc \
    --with-gnu-ld
  make
}

check() {
  make -C wslay-$pkgver
}

package() {
  cd wslay-$pkgver
  make DESTDIR="$pkgdir" install
  install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
  # rename example executables
  cd "$pkgdir/usr/bin" && find * -type f -exec mv -v {} wslay_{} \;
}
